
#ifndef __CE_PARTICELMESH_H__
#define __CE_PARTICELMESH_H__


#include <cegfx/ceexport.h>
#include <cegfx/cerendermesh.h>
#include <vector>


class CE_GFX_API ceParticelMesh : public iGeometry
{
	IQF_DECLARATION;
protected:
	LPDIRECT3DVERTEXBUFFER9					vertexBuffer;
	unsigned												numVertices;
	LPDIRECT3DINDEXBUFFER9					indexBuffer;
	unsigned												numTriangles;
	LPDIRECT3DVERTEXDECLARATION9		vertexDeclaration;
	unsigned stride;

private:
	float														particelRadius;

	ceBoundingBox										bbox;

	std::vector<D3DXVECTOR4>				positions;
	std::vector<D3DXVECTOR4>				transRotAlpha;



public:
	ceParticelMesh ();
	~ceParticelMesh ();


	bool CreateParticel (LPDIRECT3DDEVICE9 device, float w, float h);

	void ClearParticels ();
	void AddParticel (const D3DXVECTOR3& pos, const D3DXVECTOR2& trans = D3DXVECTOR2(0, 0), float rot = 0.0f, float alpha = 1.0f);
	void UpdateParticel (unsigned id, const D3DXVECTOR3& pos, const D3DXVECTOR2& trans = D3DXVECTOR2(0, 0), float rot = 0.0f, float alpha = 1.0f);
	void RemoveParticel (unsigned id);
	void SetParticelRadius (float radius);
	void UpdateBoundingBox ();


	virtual void Render (const ceRenderEnv& renderEnv);
	virtual void Update (const ceUpdateEnv& updateEnv);
	void SetBoundingBox (const D3DXVECTOR3& min, const D3DXVECTOR3& max);
	const ceBoundingBox& GetBoundingBox () const;
};


#endif /* ! __CE_INSTANCEDMESH_H__ */ 
